package com.lily.utils;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

/**
 * @author lily
 */
public class JedisUtils {

    private static JedisPool jedisPool = null;

    static {
        ResourceBundle bundle = ResourceBundle.getBundle("jedis");
        String host = bundle.getString("jedis.host");
        int port = Integer.parseInt(bundle.getString("jedis.port"));
        int maxTotal = Integer.parseInt(bundle.getString("jedis.maxTotal"));
        int maxIdle = Integer.parseInt(bundle.getString("jedis.maxIdle"));

        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(maxTotal);
        config.setMaxIdle(maxIdle);

        jedisPool = new JedisPool(config,host, port);
    }

    public static Jedis getJedis(){
        return jedisPool.getResource();
    }
}
